package com.aspire.prnp.entity;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class CreatePartition {

	public static void main(String[] args) throws Exception {

		SimpleDateFormat f = new SimpleDateFormat("yyyyMMdd");
		SimpleDateFormat f1 = new SimpleDateFormat("yyyy-MM-dd");
		 
        Date startTime = f.parse("20200518");
        Date endTime = f.parse("20200701");
        
        /*while(startTime.before(endTime)) {
        	
            Calendar c = Calendar.getInstance();
            c.setTime(startTime);
            c.add(Calendar.DAY_OF_MONTH, 1);// 今天+1天
            startTime = c.getTime();
        	String temp = f.format(startTime);
        	System.out.println("p_" + temp);
        }*/
        
        
        while(startTime.before(endTime)) {
        	
        	StringBuffer sb = new StringBuffer("ALTER TABLE exp_delivery_anjian REORGANIZE PARTITION p_max INTO( PARTITION p_");
            Calendar c = Calendar.getInstance();
            c.setTime(startTime);
            
            sb.append(f.format(startTime));
            sb.append(" VALUES LESS THAN ('");
            
            c.add(Calendar.DAY_OF_MONTH, 1);// 今天+1天
            startTime = c.getTime();
            sb.append(f1.format(startTime));
            sb.append("'), PARTITION p_max VALUES LESS THAN (MAXVALUE))");
            
        	System.out.println(sb.toString());
        }
        

	}

}
